package com.hlj.example.notification;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.os.SystemClock;

public class DownloadThread extends HandlerThread {
    public static final int TYPE_START = 1;//任务开始
    public static final int TYPE_DOWNLOADING = 2;//下载中
    public static final int TYPE_FINISHED = 3;//任务结束

    private Handler mUIHandler;
    public DownloadThread(String name) {
        super(name);
    }
    @Override
    protected void onLooperPrepared() {
        super.onLooperPrepared();
    }
    public void setUIHandler(Handler UIhandler) {
        mUIHandler = UIhandler;
    }
    public void startDownload() {
        mUIHandler.sendEmptyMessage(TYPE_START);
        int i = 1;
        while (i <= 100) {
            //模拟下载
            SystemClock.sleep(1000);
            Message message = Message.obtain();
            message.what = TYPE_DOWNLOADING;
            message.arg1 = i;
            mUIHandler.sendMessage(message);
            i++;
        }
        mUIHandler.sendEmptyMessage(TYPE_FINISHED);


    }
}

